#include "StdAfx.h"
#include "ConstructiveSolidGeometry.h"

bool IntersectionPointComp(const IntersectionPoint& lhs, const IntersectionPoint& rhs) 
{ 
	return lhs.t < rhs.t; 
}

CConstructiveSolidGeometry::CConstructiveSolidGeometry(void)
{
}


CConstructiveSolidGeometry::~CConstructiveSolidGeometry(void)
{
}

void CConstructiveSolidGeometry::Init(boost::shared_ptr<CConstructiveSolidGeometry>& spLeft,
	boost::shared_ptr<CConstructiveSolidGeometry>& spRight,
	const CColor4& vColor, const CMaterial& material)
{
	m_spLeft = spLeft;
	m_spRight = spRight;
	m_vColor = vColor;
	m_material = material;
}

DATA_TYPE CConstructiveSolidGeometry::GetMaxValue(int iAxis) const
{
	DATA_TYPE fLeftMaxValue = 0.f, fRightMaxValue = 0.f;
	if (m_spLeft)
		fLeftMaxValue = m_spLeft->GetMaxValue(iAxis);
	if (m_spRight)
		fRightMaxValue = m_spRight->GetMaxValue(iAxis);

	return __max(fLeftMaxValue, fRightMaxValue);
}

DATA_TYPE CConstructiveSolidGeometry::GetMinValue(int iAxis) const
{
	DATA_TYPE fLeftMaxValue = 0.f, fRightMaxValue = 0.f;
	if (m_spLeft)
		fLeftMaxValue = m_spLeft->GetMinValue(iAxis);
	if (m_spRight)
		fRightMaxValue = m_spRight->GetMinValue(iAxis);

	return __min(fLeftMaxValue, fRightMaxValue);
}